package com.sq.swing.sample.service;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.sq.swing.framework.exception.dao.DataNotFoundException;
import com.sq.swing.framework.exception.dao.KeyExistException;
import com.sq.swing.framework.log.Logger;
import com.sq.swing.sample.dao.IJournalDao;
import com.sq.swing.sample.entity.JournalEntity;


@Service("iJournalService")
public class JournalServiceImpl implements IJournalService {

	@Autowired
	@Qualifier("journalDao")
	private IJournalDao journalDao;
	
	protected final Logger logger = new Logger(this.getClass());
	
	public void addJournal(JournalEntity journal) {
		try {
			journalDao.insert(journal);
		} catch (KeyExistException e) {
			logger.error("addJournal", e);
		}
	}

	public void addJournalBatch(List<JournalEntity> list) {
		try {
			journalDao.insertBatch(list);
		} catch (KeyExistException e) {
			logger.error("addJournalBatch", e);
		}
	}

	public void deleteJournal(JournalEntity journal) {
		try {
			journalDao.delete(journal);
		} catch (DataNotFoundException e) {
			logger.error("deleteJournal", e);
		}
	}

	public void deleteAllJournal() {
		try {
			journalDao.deleteAll();
		} catch (DataNotFoundException e) {
			logger.error("deleteAllJournal", e);
		}
	}

	public void deleteJournalBatch(List<JournalEntity> list) {
		try {
			journalDao.deleteBatch(list);
		} catch (DataNotFoundException e) {
			logger.error("deleteJournalBatch", e);
		}
	}

	public void updateJournal(JournalEntity journal) {
		try {
			journalDao.update(journal);
		} catch (DataNotFoundException e) {
			logger.error("updateJournal", e);
		}
	}

	public JournalEntity getJournalById(String aid) {
		return journalDao.getObject(aid);
	}

	public JournalEntity getJournalById(JournalEntity journal) {
		return journalDao.getObject(journal);
	}

	public List<JournalEntity> getJournalList() {
		List<JournalEntity> list = journalDao.findList();
		return list;
	}

	public List<JournalEntity> getJournalList(JournalEntity journal) {
		List<JournalEntity> list = journalDao.findListByCondition(journal);
		return list;
	}

}
